<?php
function __autoload($file) {
    include_once $file.".php";
}
$result = '';

if ($_SERVER['REQUEST_METHOD'] == "POST") {
    if (isset($_POST['operation'])) {
        switch ((int) $_POST['operation']) {
            case 1:
                $result = "addClient.php";
                break;
            case 2:
                $result = "getClientInfo.php";
                break;
            case 3:
                $result = "putMoney.php";
                break;
            case 4:
                $result = "getMoney.php";
                break;
            case 5:
                $result = "getBalance.php";
                break;
        }
    }
    if (isset($_POST['name']) && isset($_POST['inn']) && isset($_POST['phone'])) {
        $name = $_POST['name'];
        $inn = $_POST['inn'];
        $phone = $_POST['phone'];
        $client = new Client($name,$inn,$phone);
        if (Bank::getInstance()->addClient($client)) {
            $_SESSION['num'] = $client->order;
            $result = "success.php";
        }
    }
    if (isset($_POST['orderName'])) {
        $dataClient = Bank::getInstance()->getClientByInn($_POST['orderName']);
        $dataClient = $dataClient->getClinetInfo();

        $_SESSION['dataClient'] = serialize($dataClient);
        $result = "success.php";
    }
    if (isset($_POST['addSum']) && isset($_POST['order'])) {
        if (Bank::getInstance()->putMoney($_POST['addSum'],$_POST['order'])) {
            $_SESSION['addSum'] = Bank::getInstance()->getBalance($_POST['order']);
            $result = "success.php";
        } else {
            // error
        }
    }

    if (isset($_POST['removeSum']) && isset($_POST['order'])) {
        if (Bank::getInstance()->getMoney($_POST['removeSum'],$_POST['order'])) {
            $_SESSION['removeSum'] = Bank::getInstance()->getBalance($_POST['order']);
            $result = "success.php";
        } else {
            // error
        }
    }

    if (isset($_POST['orderNum'])) {
        $_SESSION['orderNum'] = Bank::getInstance()->getBalance($_POST['orderNum']);
        $result = "success.php";
    }
}
